# 人狗交互
# class Dog:
#     d_type = '藏獒'       #类属性    公共属性
#     aaa = 'aaa'
#     def __init__(self, name, age):
#         self.name, self.age = name, age
#         print('my name is {self.name},i am {self.age}'.format(self=self))
#
#     def say_hi(self):
#         print('i am dog ,my type is ', self.d_type)
# # d1 = Dog('alex', 38)
# # d2 = Dog('jack', 40)
# #
# # d1.say_hi()
# # d2.say_hi()
# class Person:
#     sex = '男'
#     sth1, sth2, sth3 = '上山去砍柴', '开车去东北', '最爱大保健'
#
#     def __init__(self, name, age, ):
#         self.name, self.age = name, age
#         print('{self.name}, {self.age}岁, {self.sex}, {self.sth1}'.format(self=self))
#         print('{self.name}, {self.age}岁, {self.sex}, {self.sth2}'.format(self=self))
#         print('{self.name}, {self.age}岁, {self.sex}, {self.sth3}'.format(self=self))
# p1 = Person('小明', '10')
# p2 = Person('老李', '90')


# 依赖关系
# class Dog:
#     def __init__(self, name, age, breed, master):
#         self.name, self.age, self.master, self.breed = name, age, master, breed
#         self.say_hi()
#
#     def say_hi(self):
#         print('i am{self.breed},my name is{self.name},i have {self.age} years oid,'
#               'this is my master{self.master.name}'.format(self=self))
# class Person:
#     def __init__(self, name, age, sex):
#         self.name, self.age, self.sex = name, age, sex
#     def walk_dog(self, dog_obj):
#         #print('主人%s带小狗%s去溜溜' % (self.name, dog_obj.name))
#         print('主人{self.name}带小狗{dog_obj_name}去溜溜'.format(
#         self=self, dog_obj_name=dog_obj.name))
# p = Person('yyt', 22, '男')
# d = Dog('alex', 2, '二哈', p)
# p.walk_dog(d)


# 关联关系
# class Relation:
#     def __init__(self):                       #建立关联关系
#         self.cp = []
#     def make_cp(self,obj1,obj2):                #成为男女朋友
#         self.cp.append(obj1)
#         self.cp.append(obj2)
#         print('{0}和{1}成了男女朋友'.format(obj1.name, obj2.name))
#     def get_p(self,obj):                   #得到某人的对象
#         for i in self.cp:
#             if obj != i:
#                 return i
#         else:
#             print('有没有对象心里没B数吗！！！')
#     def break_up(self):                    #分手
#         if self.cp:
#             print('{0}和{1}分手了....'.format(self.cp[0].name, self.cp[1].name))
#             self.cp.clear()
#         else:
#             print('你有对象吗？？？就分手')
# class Person:
#     def __init__(self, name, sex, age, relation):
#         self.name, self.sex, self.age = name, sex, age
#         self.relation = relation                    #关系的连接
# relation_2 = Relation()
# p1 = Person('yyt', 'M', 22, relation_2)
# p2 = Person('xlk', 'F', 20, relation_2)
# relation_2.make_cp(p1, p2)
# print('{0}是{1}的女朋友'.format(p1.relation.get_p(p1).name, p1.name))
# p1.relation.break_up()


# 组合关系
# class Dog:
#     def __init__(self, name, attack_val):
#         self.name, self.live_val, self.attack_val = name, 100, attack_val
#     def bite(self,obj):
#         obj.live_val -= self.attack_val
#         print('{0}被{1}咬中，掉血{2}，还剩{3}血'.format(obj.name, self.name, self.attack_val, obj.live_val))
# class Person:
#     def __init__(self, name, age):
#         self.name, self.age,self.live_val = name, age, 100
#         self.weapon = Weapon()
#         if self.age > 18 and self.age < 40:
#             self.attack_val = 20
#         else:
#             self.attack_val = 5
#     def attack(self, obj):
#         obj.live_val -= self.attack_val
#         print('{0}被{1}击中，掉血{2}，还剩{3}血'.format(obj.name, self.name, self.attack_val, obj.live_val))
# class Weapon:
#     def gun(self, obj):
#         self.name = 'ak47'
#         self.attack_val = 100
#         obj.live_val -= self.attack_val
#         self.print_log(obj)
#     def knife(self, obj):
#         self.name = '小刀'
#         self.attack_val = 50
#         obj.live_val -= self.attack_val
#         self.print_log(obj)
#     def stick(self, obj):
#         self.name = '棒'
#         self.attack_val = 30
#         obj.live_val -= self.attack_val
#         self.print_log(obj)
#     def print_log(self, obj):
#         print('{0}被{1}击中，掉血{2}，还剩{3}血'.format(obj.name, self.name, self.attack_val, obj.live_val))
# d = Dog('alex', 30)
# p = Person('yyt', 22)
# d.bite(p)
# p.weapon.gun(d)


# 继承
# class Animal:
#     a_type = '哺乳动物'
#     def __init__(self, name, age, sex):
#         self.name, self.age, self.sex = name, age, sex
#         print('父类程序')
#     def eat(self):
#         print('{0} is eating'.format(self.name))
# class Person(Animal):
#     def __init__(self, name, age, sex, hobbies):
#         # Animal.__init__(self, name, age, sex)
#         # super().__init__(name, age, sex)
#         super(Person, self).__init__(name, age, sex)
#         self.hobbies = hobbies
#         print('子类程序')
#     def eat(self):
#         super(Person, self).eat()
#         print('2222')
# class Dog(Animal):
#     a_type = 'dog'
#     def play(self):
#         print('{0} is playing'.format(self.name))
# p = Person('alex', 38, 'M', '打球')
# d = Dog('mjj', 3, 'F')
# p.eat()
# print(p.a_type)
# d.play()
# d.eat()
# print(d.a_type)


# cs
# class Person:
#     live_val = 100
#     def __init__(self,name, job):
#         self.name, self.job = name, job
#         self.weapon = Weapon()
# class Weapon:
#     def knife(self,obj):
#         self.name = '小刀'
#         self.attavk_val = 50
#         obj.live_val -= self.attavk_val
#         self.print_log(obj)
#     def gun_T(self,obj):
#         self.name = 'ak47'
#         self.attavk_val = 100
#         obj.live_val -= self.attavk_val
#         self.print_log(obj)
#     def gun_CT(self,obj):
#         self.name = 'm4a1'
#         self.attavk_val = 90
#         obj.live_val -= self.attavk_val
#         self.print_log(obj)
#     def c4(self,obj):
#         self.name = 'c4'
#         if obj.job == 'ct':
#             print('你不能使用c4炸药包')
#             return None
#         else:
#             exit('c4安装成功，所有人清除')
#     def print_log(self,obj):
#         print('使用{}击中{}掉血{}，还剩{}血'.format(self.name,obj.name,self.attavk_val,obj.live_val))
# t1 = Person('t1', 't')
# t2 = Person('t2', 't')
# t3 = Person('t3', 't')
# t4 = Person('t4', 't')
# t5 = Person('t5', 't')
# ct1 = Person('ct1', 'ct')
# ct2 = Person('ct2', 'ct')
# ct3 = Person('ct3', 'ct')
# ct4 = Person('ct4', 'ct')
# ct5 = Person('ct5', 'ct')
# t1.weapon.gun_T(ct3)
# ct2.weapon.gun_CT(t1)
# ct1.weapon.gun_CT(t1)
# t4.weapon.gun_T(ct2)
# t5.weapon.knife(ct5)
# t4.weapon.c4(t4)


# c3算法用mro查找顺序
# print(obj.mro())


# 封装      通过改成私有使外面数据无法改变对象，使用封装技术修改数据       实例名._类名+私有属性/方法名  可以修改数据
# class Person:
#     def __init__(self, name, age):
#         self.name = name
#         self.age = age
#         self.__live_val = 100
#     def get_live_val(self):
#         print('有%s'%(self.__live_val))
#         self.__breath()
#     def got_attack(self):
#         self.__live_val -= 20
#         print('受到伤害还有%s血'%(self.__live_val))
#     def __breath(self):
#         print('i am breathing')
# p = Person('yyt',22)
# print(p.name)
# #print(p.__live_val)     不行
# p.get_live_val()
# p.got_attack()
# p._Person__live_val = 200            #实例名._类名+私有属性/方法名  可以修改数据
# p._Person__breath()             #实例名._类名+私有属性/方法名     直接在外部调用
# p.get_live_val()


# 多态
# class Document:
#     def __init__(self, name):
#         self.name = name
#     def show(self):
#         raise NotImplementedError("Subclass must implement abstract method")
# class Pdf(Document):
#     def show(self):
#         return 'Show pdf contents!'
# class Word(Document):
#     def show(self):
#         return 'Show word contents!'
# pdf = Pdf('111.pdf')
# word = Word('222.doc')
# d = [pdf, word]
# for i in d:
#     print(i.show())


# 类、对象、实例、实例化有什么关系？   类是设计方案 对象是一个通过设计方案实例化出来的实例
# 类属性和实例属性有什么区别？       类属性只有通过设计方案本身修改 实例的self.xxx是实例属性
